//Ta Duc Viet
//Tinh trung binh va do lech chuan
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void test_1_value( int &, int &); 
void test_2_value( int &, int &, int &);
void test_3_value( int &, int &, int &, int &);
void test_4_value( int &, int &, int &, int &, int &);
float average( int, int n);
float standard_deviation (int n, int &a, int &b, int &c, int &d);
int main(){
	int n, a, b, c, d;
	a = b = c = d = 0;
	int sum = 0;
	cout << "This program tests my two new functions." << endl;
	do {
		cout << "Do you wish to test 1, 2, 3 or 4 numbers (enter 0 to end the program):";
		cin >> n;
		float a[4] = { 0 };
		if ( n > 4 || n < 0){
			cout << "Sorry, the program can only test 1, 2, 3 or 4 values." << endl;
			continue;
			}
		switch (n){
		case 1:
            sum = 0;
			test_1_value(sum);
			cout << "Average: " << average( sum, n) << endl;
			break;
		case 2:
            sum = 0;
			test_2_value(sum);
			cout << "Average: " << average( sum, n) << endl;
			break;
		case 3:
            sum = 0;
			test_3_value( sum);
			cout << "Average: " << average( sum, n) << endl;
			break;
		case 4:
            sum = 0;
			test_4_value( sum);
			cout << "Average: " << average( sum, n) << endl;
			break;
		}
		}
		while ( n != 0); 
	cout << "Finished testing." << endl;
	system ("pause");
	return 0;
}
void test_1_value( int &sum, int &a){
	cout << "Enter first value:";
	cin >> a;
	sum = sum + a;
}
void test_2_value( int &sum, int &a, int &b){
	cout << "Enter first value:";
	cin >> a;
	sum = sum + a;
	cout << "Enter second value:";
	cin >> b;
	sum = sum + b;
}
void test_3_value( int &sum, int &a, int &b, int &c){
	cout << "Enter first value:";
	cin >> a;
	sum = sum + a;
	cout << "Enter second value:";
	cin >> b;
	sum = sum + b;
	cout << "Enter third value:";
	cin >> c;
	sum = sum + c;
}
void test_4_value( int &sum, int &a, int &b, int &c, int &d){
	cout << "Enter first value:";
	cin >> a;
	sum = sum + a;
	cout << "Enter second value:";
	cin >> b;
	sum = sum + b;
	cout << "Enter third value:";
	cin >> c;
	sum = sum + c;
	cout << "Enter fourth value";
	cin >> d;
	sum = sum + d;
}
float average( int sum, int n){
	return sum / n;
}
float standard_deviation (int n, int sum, int &a, int &b, int &c, int &d){
      float ave;
	ave = average(sum, n);
	for ( int i = 0; i < n; i++){
		sum = sum + pow (a[i] - ave,2);
	}
	return sqrt( sum / n);
